/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package leagueControllers;
/**
 *
 * @author ali
 */
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import leagueViews.Login;

public class LoginC {
    private Login view;
    private ActionListener actionListener;
    private final String username = "admin";
    private final String password = "admin";
    
    
    
    public LoginC (Login view){
        this.view = view;
    }
    
    
    public void login(){
        if (username.equals(view.getUsername())&&password.equals(view.getPassword())){
            // grant access to program
            //view.setVisible(false);
            System.out.println("logged in");
            view.setVisible(false);
            }
        else 
            JOptionPane.showMessageDialog(view, "Incorrect username or password");
    }
    
    public void control(){
        actionListener = new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent actionEvent) {                  
                  login();
              }
        };
        view.getButton().addActionListener(actionListener); 
    }
    
    public static void main(String[] args) {           
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {    
                System.out.println("dlfkdff");
                //Model model = new Model(0);
                Login view = new Login(); 
                LoginC controller = new LoginC(view);
                controller.control();
            }
        });  
    }
}
